/**
 * @format
 * @Author: TC
 * @Date: 2021-09-27 18:10:15
 * @Last Modified by: TC
 * @Last Modified time: 2023-10-23 20:20:34
 */

import {
    _decorator,
    Asset,
    Button,
    Camera,
    color,
    Component,
    EffectAsset,
    EPhysics2DDrawFlags,
    EventTouch,
    instantiate,
    Material,
    Node,
    physics,
    PhysicsSystem,
    PhysicsSystem2D,
    Prefab,
    Texture2D,
    v3,
    view,
} from "cc";
import { app } from "../../FrameWork/App";
import { BaseScene } from "../../FrameWork/Module/Component/BaseScene";
import { ASSERT_TYPE } from "../../FrameWork/Module/Res/ResConst";
import { gameDataMgr } from "../_Common/Manager/GameDataManager";
import { nsBundleConst } from "../Const/BundleConst";
import { GAME_STATE } from "../Const/EnumConst";
import { SceneAndWindowConst } from "../Const/SceneAndWindowConst";
import { SoundConst } from "../Const/SoundConst";
import { GameTool } from "../Extend/GameTool";
const { ccclass, property } = _decorator;

@ccclass("GameScene")
export class GameScene extends BaseScene {
    @property(Node)
    content: Node = null;

    private _timerId: number = -1;

    onLoad() {
        super.onLoad();
        gameDataMgr.init();
        app.inputMgr.open();
        gameDataMgr.gameState = GAME_STATE.GAME;
        gameDataMgr.currScene = "game";

        // PhysicsSystem2D.instance.enable = true;
        // PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Shape || EPhysics2DDrawFlags.Aabb;

        // tApp.soundMgr.playMusic(SoundConst.MAIN_BG);
        // tApp.loaderMgr.loadAsset(mBundleConst.Shader, "2D/Gray/gray", ASSERT_TYPE.MATERIAL, (mtl: Material) => {
        //     tApp.postEffectMgr.open(tApp.sceneMgr.getCurrScene().getChildByName("Main Camera").getComponent(Camera), mtl);
        //     tApp.shaderMgr.setTextureProperty(mtl, "MainTexture", tApp.postEffectMgr.peSprite.spriteFrame.texture as Texture2D);
        // });
        app.resMgr.loadPrefab(nsBundleConst.Role, "10001/Prefab/char", (p: Prefab) => {
            let char = instantiate(p);
            gameDataMgr.getCanvas().addChild(char);
        });
        // this._timerId = tApp.timerMgr.schedule(this.tick, this, null, 0, -1, 0);
    }

    onExit(e: EventTouch): void {
        GameTool.playButtonSound();
        app.sceneMgr.runScene(SceneAndWindowConst.MAIN_SCENE, nsBundleConst.Hall);
    }

    onDestroy() {
        super.onDestroy();
        app.timerMgr.unschedule(this._timerId);
        app.resMgr.getBundle(nsBundleConst.Game).releaseAll();
    }
}
